/*
 * @Author: AiLjx
 * @Date: 2022-08-02 15:17:12
 * @LastEditors: AiLjx
 * @LastEditTime: 2022-08-02 21:31:12
 */
import { getMvUrl } from "../../api.js";

SPA_RESOLVE_INIT = async function (transition) {
    // transition为路由参数字符串
    // SPA_RESOLVE_INIT里的函数只有当路由加载完毕后才会触发
    // 在这里这里获取Dom元素，发起axios请求（因为SPA_RESOLVE_INIT函数能直接设置async，其内部就能直接使用await了）
    console.log(3);

    const mvVideo = document.getElementsByClassName("mvVideo")[0];
    const btn = document.getElementsByClassName("btn")[0];

    document.getElementsByTagName("p")[0].innerHTML =
        "当前详情页路由参数" + JSON.stringify(transition);

    const data = await getMvUrl(transition.query.id);
    mvVideo.setAttribute("src", data.url);

    btn.onclick = () => {
        if (mvVideo.clientWidth > 400) {
            mvVideo.style.width = "400px";
        } else {
            mvVideo.style.width = "";
        }
    };
};

console.log(2);
